<template>
  <div class="container">
    <div class="background-animations">
      <div class="cube"></div>
      <div class="cube"></div>
      <div class="cube"></div>
    </div>
    <div class="login-box animate__animated animate__fadeIn animate__faster">
      <div class="header-section">
        <div class="logo-container">
          <img :src="require('../assets/imgs/logo.png')" alt="Admin Logo" class="logo-img"/>
        </div>
        <div class="title-container">
          <div class="title">系统管理控制台</div>
          <div class="subtitle">Computer Repair Management Console</div>
        </div>
      </div>

      <el-form :model="form" :rules="rules" ref="formRef">
        <el-form-item prop="username">
          <el-input 
            prefix-icon="el-icon-user" 
            placeholder="请输入管理员账号" 
            v-model="form.username"
            class="custom-input">
          </el-input>
        </el-form-item>
        
        <el-form-item prop="password">
          <el-input 
            prefix-icon="el-icon-lock" 
            placeholder="请输入管理员密码" 
            show-password  
            v-model="form.password"
            class="custom-input">
          </el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" class="login-btn" @click="login">
            <span>管理员登录</span>
          </el-button>
        </el-form-item>
        
        <div class="security-tips">
          <i class="el-icon-warning-outline"></i>
          请注意信息安全，切勿泄露管理员密码
        </div>
      </el-form>
    </div>
    
    <div class="tech-circles">
      <div class="circle"></div>
      <div class="circle"></div>
    </div>
    
    <div class="footer">
      <div class="copyright">
        广软计算机协会 © 2025
        <a href="http://ca.seig.edu.com" target="_blank" class="footer-link">ca.seig.edu.com</a>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "AdminLogin",
  data() {
    return {
      form: {
        username: '',
        password: '',
        role: 'ADMIN' // 固定为ADMIN角色
      },
      rules: {
        username: [
          { required: true, message: '请输入管理员账号', trigger: 'blur' },
          { min: 4, message: '账号长度不能小于4位', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入管理员密码', trigger: 'blur' },
          { min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    login() {
      this.$refs['formRef'].validate((valid) => {
        if (valid) {
          this.$request.post('/login', this.form).then(res => {
            if (res.code === '200') {
              let user = res.data
              if (!user.token) {
                user.token = res.token || 'ADMIN-token'
              }
              localStorage.setItem("xm-user", JSON.stringify(user))
              this.$router.push('/home')
              this.$message.success('管理员登录成功')
            } else {
              this.$message.error(res.msg || '登录失败，请检查账号密码')
            }
          }).catch(err => {
            this.$message.error('登录失败，请检查网络连接')
          })
        }
      })
    }
  }
}
</script>

<style scoped>
.container {
  height: 100vh;
  overflow: hidden;
  background: linear-gradient(135deg, #1a2a3a 0%, #2d4356 100%);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
}

/* 背景动画效果 */
.background-animations {
  position: absolute;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 0;
}

.cube {
  position: absolute;
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(5px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  animation: float 15s infinite;
}

.cube:nth-child(1) {
  width: 100px;
  height: 100px;
  top: 20%;
  left: 10%;
  animation-delay: 0s;
}

.cube:nth-child(2) {
  width: 150px;
  height: 150px;
  top: 40%;
  right: 15%;
  animation-delay: -5s;
}

.cube:nth-child(3) {
  width: 80px;
  height: 80px;
  bottom: 20%;
  left: 20%;
  animation-delay: -10s;
}

@keyframes float {
  0%, 100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-20px) rotate(45deg);
  }
}

/* 登录框样式优化 */
.login-box {
  width: 420px;
  padding: 40px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  border-radius: 16px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
  position: relative;
  z-index: 1;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Logo和标题区域 */
.header-section {
  text-align: center;
  margin-bottom: 35px;
}

.logo-container {
  margin-bottom: 20px;
}

.logo-img {
  width: 80px;
  height: 80px;
  object-fit: contain;
}

.title {
  font-size: 28px;
  font-weight: 600;
  color: #1a2a3a;
  margin-bottom: 8px;
  letter-spacing: 1px;
}

.subtitle {
  font-size: 15px;
  color: #666;
  margin-bottom: 35px;
  letter-spacing: 0.5px;
}

/* 输入框样式优化 */
.custom-input :deep(.el-input__inner) {
  height: 50px;
  border-radius: 10px;
  border: 2px solid #e8eef3;
  background: rgba(255, 255, 255, 0.9);
  padding-left: 45px;
  transition: all 0.3s ease;
  font-size: 15px;
}

.custom-input :deep(.el-input__inner):focus {
  border-color: #2d4356;
  box-shadow: 0 0 12px rgba(45, 67, 86, 0.1);
}

.custom-input :deep(.el-input__prefix) {
  left: 15px;
}

/* 登录按钮样式 */
.login-btn {
  width: 100%;
  height: 50px;
  font-size: 16px;
  font-weight: 500;
  background: linear-gradient(45deg, #2d4356, #435B66);
  border: none;
  border-radius: 10px;
  margin-top: 15px;
  transition: all 0.3s ease;
  letter-spacing: 1px;
}

.login-btn:hover {
  background: linear-gradient(45deg, #435B66, #2d4356);
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(45, 67, 86, 0.2);
}

/* 安全提示样式 */
.security-tips {
  text-align: center;
  color: #666;
  font-size: 13px;
  margin-top: 25px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e8eef3;
}

.security-tips i {
  margin-right: 6px;
  color: #e74c3c;
}

/* 页脚样式 */
.footer {
  position: absolute;
  bottom: 20px;
  width: 100%;
  text-align: center;
}

.copyright {
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
}

.footer-link {
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  margin-left: 5px;
  transition: color 0.3s ease;
}

.footer-link:hover {
  color: #fff;
}

/* 科技感圆圈装饰 */
.tech-circles {
  position: absolute;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.circle {
  position: absolute;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.1);
}

.circle:nth-child(1) {
  width: 300px;
  height: 300px;
  top: -150px;
  right: -150px;
  border-color: rgba(255, 255, 255, 0.05);
}

.circle:nth-child(2) {
  width: 200px;
  height: 200px;
  bottom: -100px;
  left: -100px;
  border-color: rgba(255, 255, 255, 0.03);
}
</style> 